/* linkit.js
 * By François Leporcq
 * MIT Licensed.
 */
var Link = AbstractLink.extend({
    _className: "Link",
    init: function(startPolygon, endPolygon, startLabel, endLabel, midLabel, start, end){
        this._start = start;
        this._end = end;
        this._line = new Line(this._start, this._end);
        this._startPolygon = startPolygon;
        this._endPolygon = endPolygon;
        this._startLabel = startLabel;
        this._endLabel = endLabel;
        this._midLabel = midLabel;
        this.setShapes(this.getShapes());
        this._updateStartPolygon();
        this._updateEndPolygon();
        this._updateStartLabel();
        this._updateEndLabel();
        this._updateMidLabel();
    },
    setStart: function(start){
        this._start = start;
        this._line.setStart(start);
        this._updateStartPolygon();
        this._updateEndPolygon();
        this._updateStartLabel();
        this._updateEndLabel();
        this._updateMidLabel();
    },
    setEnd: function(end){
        this._end = end;
        this._line.setEnd(end);
        this._updateStartPolygon();
        this._updateEndPolygon();
        this._updateStartLabel();
        this._updateEndLabel();
        this._updateMidLabel();
    },
    _updateStartPolygon: function(){
        if(this._startPolygon != null && this._start != null && this._end != null){
            this._startPolygon.setOrigin(this._start);
            this._startPolygon.resetRotation();
            this._startPolygon.rotate(270-this._line.getXAxisTheta());
        }
    },
    _updateEndPolygon: function(){
        if(this._endPolygon != null && this._end != null && this._end != null){
            this._endPolygon.setOrigin(this._end);
            this._endPolygon.resetRotation();
            this._endPolygon.rotate(90-this._line.getXAxisTheta());
        }
    }
});